﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Task.Entity.Config;
using System.Xml.Linq;
using Task.Log;

namespace Task.Quartz.Example
{
    public class HandlerXML
    {
        public static TaskRoot GetTaskRoot()
        {
            try
            {
                TaskRoot taskRoot = new TaskRoot();

                XElement rootNode = XElement.Load(AppDomain.CurrentDomain.BaseDirectory + "/Configs/HandlerXML.xml");
                IEnumerable<XElement> targetNodes = from target in rootNode.Descendants("Handler")
                                                    select target;
                foreach (XElement node in targetNodes)
                {
                    taskRoot.Add(new HandlerConfig()
                    {
                        Assembly = node.Element("Assembly").Value,
                        Type = node.Element("Type").Value,
                        WithCronSchedule = node.Element("WithCronSchedule").Value,
                    });
                }
                return taskRoot;
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.ToString(), System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                return null;
            }
        }
    }
}
